package com.manong.bookstore.store.service.impl;

import com.alibaba.nacos.client.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manong.common.utils.PageUtils;
import com.manong.common.utils.Query;

import com.manong.bookstore.store.dao.StoreDao;
import com.manong.bookstore.store.entity.StoreEntity;
import com.manong.bookstore.store.service.StoreService;


@Service("storeService")
public class StoreServiceImpl extends ServiceImpl<StoreDao, StoreEntity> implements StoreService {

    @Autowired
    private StoreService storeService;

//    @Override
//    public PageUtils queryPage(Map<String, Object> params) {
//        IPage<StoreEntity> page = this.page(
//                new Query<StoreEntity>().getPage(params),
//                new QueryWrapper<StoreEntity>()
//        );
//
//        return new PageUtils(page);
//    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        //1、获取key
        String key = (String) params.get("key");
        QueryWrapper<StoreEntity> queryWrapper = new QueryWrapper<>();

        if(!StringUtils.isEmpty(key)){
            queryWrapper.eq("store_id",key)
                    .or().eq("storekeeper_id",key)
                    .or().eq("classify_id",key)
                    .or().eq("store_integrity",key)
                    .or().like("store_name",key)
                    .or().like("store_desc",key)
                    .or().like("store_anno",key)
                    .or().like("store_location",key)
                    .or().like("store_address",key)
                    .or().like("store_phone",key);
        }

        IPage<StoreEntity> page = this.page(
                new Query<StoreEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public StoreEntity getByStoreKeeperId(Integer storekeeperId) {
        QueryWrapper<StoreEntity> wrapper=new QueryWrapper<StoreEntity>().eq("storekeeper_id",storekeeperId);

        return storeService.getOne(wrapper);
    }

}